import Joi, { boolean, number } from 'joi';

const modelTypes = ['local', 'remote'];
const resultTypes = ['file', 'param'];
const inputTypes = ['manual', 'batch'];

const stringArraySchema = Joi.array().items(Joi.string());

export let simConfigSchema = Joi.object().keys({
  model: Joi.object({
    type: Joi.string().allow(...modelTypes).required(),
    file: Joi.string().required(),
    entry: Joi.string().allow(''),
    name: Joi.string().allow('')
  }),

  input: Joi.array().items({
    id: Joi.string().allow(''),
    name: Joi.string().required(),
    value: Joi.any().required(),
    org: Joi.string().required(),
    unit: Joi.string().allow(''),
    type: Joi.string().allow(''),
    mdoLabel: Joi.string().allow('')
  }),

  output: Joi.array().items({
    id: Joi.string().allow(''),
    name: Joi.string().required(),
    unit: Joi.string().allow(''),
    mdoLabel: Joi.string().allow('')
  }),

  result: Joi.object({
    nativePath: Joi.string().allow('')
  }),

  task: Joi.object({
    desc: Joi.string().allow('')
  }),

  simServerIdentity: Joi.array().allow(null),

  inputSetup: Joi.object({
    type: Joi.string().allow(...inputTypes),
    inputFile: Joi.object({
      name: Joi.string().allow(''),
      ossPath: Joi.string().allow('')
    }).allow(null)
  }),

  outputSetup: Joi.object({
    type: stringArraySchema,
    paramType: Joi.string().allow(''),
    outputFile: Joi.object({
      name: Joi.string().allow(''),
      ossPath: Joi.string().allow('')
    }).allow(null)
  }),

  config: Joi.object({
    timeout: Joi.number().allow(null)
  }),

  openGui: Joi.boolean().default(false),

  extra: Joi.object({
    runOption: Joi.string().allow('')
  })

});